package day02;

import javax.swing.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.stream.Collectors;

public class Dome01 {
    public static void main(String[] args) {
    //1.创建窗口
        JFrame frame = new JFrame("🐏了个🐏");
    //2.创建画板
        JPanel panel = new JPanel();
        panel.setSize(840,800);
        frame.add(panel);
            //取消面板默认设置
        panel.setLayout(null);


    //3.绘制背景图
        JLabel background = new JLabel(new ImageIcon("res/背景.jpg"));
        background.setSize(480,800);
        panel.add(background);

    //4.绘制卡牌
        String [] names  = {
                "兔子","刷子","剪刀","南瓜","奶瓶","帽子","干草","手套","月饼","树",
                "树桩","栗子","毛线","水桶","火堆","白菜","耙子","苹果","草","萝卜",
                "蜜蜂","酒坛","铃铛","面具","饭团"
        };

        //创建牌
        //创建一个集合,收集全部的牌
        ArrayList<JButton> cards = new ArrayList<>();
        //将卡牌添加到集合中
        for (int j = 0; j < 6; j++) {
            for (int i = 0; i < names.length; i++) {
                String filename = "res/" + names[i] + ".png";
                System.out.println(filename);
                JButton card = new JButton(new ImageIcon(filename));
                card.setSize(59, 66);
                cards.add(card);
            }
        }
        //洗牌
        Collections.shuffle(cards);//将元素中的顺序打乱
        //顺序摆牌
        for (int i = 0; i < 49; i++) {
            //取出集合中的每一个元素
            JButton card = cards.get(i);
            //设置卡牌按钮的位置
            card.setLocation(30+(i%7)*59,100+(i/7)*66);
            //将卡牌添加到面板上
            panel.add(card,0);
        }
        for (int i = 0; i < 36 ; i++) {
            //取出集合中的每一个元素
            JButton card = cards.get(i+49);
            //设置卡牌按钮的位置
            card.setLocation(30+30+(i%6)*59,100+30+(i/6)*66);
            //将卡牌添加到面板上
            panel.add(card,0);
        }
        for (int i = 0; i < 35 ; i++) {
            //取出集合中的每一个元素
            JButton card = cards.get(i+49+36);
            //设置卡牌按钮的位置
            card.setLocation(30+(i%7)*59,100+60+(i/7)*66);
            //将卡牌添加到面板上
            panel.add(card,0);
        }










        frame.setSize(495,800);
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}
